/*
 * OpenParts
 * A dynamic-loading components framework for GWT
 * Copyright (C) 2011 Christophe Bouthier  [chris{AT}binary-gastronome{DOT}fr]
 *
 * This work is partially based on work I have done at INRIA (http://www.inria.fr) 
 * in the context of the Qualipso European Project (http://qualipso.org/),
 * The work done at INRIA is Copyright (C) 2006-2011 INRIA
 *
 * This work is distributed under the LGPL version 3
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation. See the GNU
 * Lesser General Public License in LGPL.txt for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package fr.openparts.opshowcase.messagecontainer.client.presenter;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;

import fr.openparts.OpenParts.client.OPBinder;
import fr.openparts.OpenParts.client.OPParams;
import fr.openparts.OpenParts.client.OPShell;
import fr.openparts.OpenParts.client.OPSlot;
import fr.openparts.OpenParts.client.OPSlotProxy;
import fr.openparts.OpenParts.client.annotations.OPServiceName;
import fr.openparts.OpenParts.client.annotations.OPViewFactory;
import fr.openparts.opshowcase.messagecontainer.client.view.MessageContainerEmbeddedView;
import fr.openparts.opshowcase.messagecontainer.client.view.MessageContainerView;

/**
 * Presenter of Container for Message Dispatching, for OpenParts Showcase
 * 
 * @author Christophe Bouthier [chris{AT}binary-gastronome{DOT}fr]
 * @creation.date 24 January 2011
 */
@OPServiceName("messagecontainer")
public class MessageContainerPresenter implements EntryPoint {

    public interface MessageContainerPresenterBinder extends OPBinder<MessageContainerPresenter> {}
    public final static MessageContainerPresenterBinder binder = GWT.create(MessageContainerPresenterBinder.class);

    protected MessageContainerView view;

    /**
     * Entry point, method called when the module is loaded.
     * 
     * @see com.google.gwt.core.client.EntryPoint#onModuleLoad()
     */
    @Override
    public void onModuleLoad() {
        binder.bindPart(this);
        view = new MessageContainerView(this);
        binder.notifyLoadingCompleted();
    }

    /**
     * Returns the container view
     * 
     * @param params
     *            not used here
     * @return the container view
     */
    @OPViewFactory(resourceName = "messagecontainer", actionName = OPShell.ACTION_DISPLAY)
    public Widget getContainerView(final OPParams params, final OPSlotProxy proxy) {
        return view;
    }

    /**
     * Display the embedded view for message dispatching in the given container
     * 
     * @param container
     *            the container for the embedded view.
     */
    public void displayEmbeddedView(final MessageContainerEmbeddedView container) {
        final OPSlot slot = OPShell.getSlot("messageembedded", "messageembedded", OPShell.ACTION_DISPLAY);
        container.setSlot(slot);
        OPShell.displayView("messageembedded", "messageembedded", OPShell.ACTION_DISPLAY, slot, new OPParams("id", String.valueOf(container.getId())));
    }

}
